package cn.sccl.common.scaffold.filegens;


import cn.sccl.common.scaffold.FileConfig;
import cn.sccl.common.util.StrUtils;
import cn.sccl.common.scaffold.FileGenerator;

import java.util.HashMap;
import java.util.Map;

/**
 * 模型类的文件生成器
 * Created by 杨浩宇 on 2016-02-20.
 */
public class MapperFileGenerator extends FileGenerator {

    @Override
    public String getTemplate() {
        // 如果是oracle，请修改为mapper-oracle.ftl
        return "mapper.ftl";
    }

    @Override
    public boolean storeToJavaSrc() {
        return false;
    }

    @Override
    public String getTargetPath(String projectPath, String packagePath, String modelName) {
        return projectPath + "/" + packagePath + "/dao/" + modelName + "DAO.xml";
    }

    @Override
    public Map fillParams(FileConfig f) {
        Map map = new HashMap();
        map.put("package", f.getBasePackage() + ".model");
        map.put("daoClass", f.getBasePackage() + ".dao." + f.getModelName() + "DAO");
        map.put("tableName", f.getTableInfo().getTableName());
        map.put("modelClass", f.getBasePackage() + ".model." + f.getModelName());
        map.put("modelName", f.getModelName());
        map.put("primaryKey", f.getTableInfo().getPrimaryKey());
        map.put("primaryKeyProperty", StrUtils.toCamelCase(f.getTableInfo().getPrimaryKey()));

//        List<ModelProperty> properties = new ArrayList<ModelProperty>();
//        for (ColumnInfo columnInfo : f.getTableInfo().getColumnInfos()) {//列信息转换为模型类的属性。
//            ModelProperty p = new ModelProperty(columnInfo.toJavaType().getName(), StrUtils.toCamelCase(columnInfo.getColumnName().toLowerCase()), columnInfo.getComments() , columnInfo.getColumnName() , columnInfo.getJdbcType());
//            properties.add(p);
//        }
        map.put("columns", f.getTableInfo().getColumnInfos());
        return map;
    }


}
